import axios from "axios";

// const BANGUMI_URL = "http://192.168.31.55:5000";
const BANGUMI_URL = "http://192.168.31.118:8083";
// const BANGUMI_URL = "http://47.113.227.183:8083";

export default {

    //获取每周番剧数据
    async getDailyBangumi() {
        return await axios
            .get(BANGUMI_URL + "/get_dailyList")
            .then((res) => {
                let display, today;
                for (let i = 0; i < res.data.length; i++) {
                    if (res.data[i].is_today == 1) {
                        display = i;
                        today = res.data[i];
                    }
                }
                return { display: display, today: today, data: res.data }
            })
            .catch((err) => {
                return err;
            });
    },


    // 搜索符合条件的番剧
    async serachBangumi(area, state, year, style, order, page) {
        return await axios
            .get(BANGUMI_URL + "/filter", {
                params: {
                    area: area,
                    status: state,
                    year: year,
                    style: style,
                    order: order,
                    page: page,
                }
            })
            .then((res) => {
                return res.data;
            })
            .catch((err) => {
                return err
            });
    },

    //获取番剧详情
    async getBangumiInfo(id, type) {
        return await
            axios
                .get(BANGUMI_URL + "/fanju", {
                    params: {
                        id: id,
                        type: type
                    }
                })
                .then((res) => {
                    return res.data;
                })
                .catch((err) => {
                    return err;
                });
    },

    //番剧搜索
    async bangumiSearch(text, page) {
        return await
            axios
                .get(BANGUMI_URL + "/search", {
                    params: {
                        text: text,
                        page: page
                    }
                })
                .then((res) => {
                    return res.data;
                })
                .catch((err) => {
                    return err;
                });
    },

    //获取番剧元数据
    async bangumiSimple(id) {
        return await
            axios
                .get(BANGUMI_URL + "/fanju_simple", {
                    params: {
                        id: id
                    }
                })
                .then((res) => {
                    return res.data.media;
                })
                .catch((err) => {
                    return err;
                });
    },

}


